<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

/**
 * 部门控制器
 */
class Branch extends AdminBase
{

    /**
     * 部门列表
     */
    public function branchList()
    {
        $where = $this->logicBranch->getWhere($this->param);
        $list=$this->logicBranch->getBranchList($where);
        if(IS_POST){
            return json($list);
        }else{
            $this->assign('list',$list);
            foreach ($list as $key => $value) {
                $list[$key]['num']=$this->logicStaff->staffNum('branch',$value['id'])['num'];
            }
            return $this->fetch('branch_list');
        }
        
    }
    
    /**
     * 部门导出
     */
    public function exportBranchList()
    {
        
        $where = $this->logicBranch->getWhere($this->param);
        
        $this->logicBranch->exportBranchList($where);
    }

    /**
     * 部门添加
     */
    public function branchAdd()
    {
        
        IS_POST && $this->jump($this->logicBranch->branchAdd($this->param));
        $this->assign('company_list', $this->logicCompany->getCompanyList());
        return $this->fetch('branch_add');
    }
    
    /**
     * 部门编辑
     */
    public function branchEdit()
    {
        
        IS_POST && $this->jump($this->logicBranch->branchEdit($this->param));
        
        // var_dump($this->param);exit();
        $this->assign('company_list', $this->logicCompany->getCompanyList());
        $info = $this->logicBranch->getBranchInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('branch_edit');
    }
    
    /**
     * 部门删除
     */
    public function branchDel($id = 0)
    {
        
        return $this->jump($this->logicBranch->branchDel(['id' => $id]));
    }
}
